<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml"/>

    <xsl:template name="formatdate">
        <xsl:param name="datestr" />
        <xsl:variable name="mm">
            <xsl:value-of select="substring($datestr,6,2)" />
        </xsl:variable>
        <xsl:variable name="dd">
            <xsl:value-of select="substring($datestr,9,2)" />
        </xsl:variable>
        <xsl:variable name="yyyy">
            <xsl:value-of select="substring($datestr,1,4)" />
        </xsl:variable>
        <xsl:variable name="hh">
            <xsl:value-of select="substring($datestr,12,2)" />
        </xsl:variable>
        <xsl:variable name="mimi">
            <xsl:value-of select="substring($datestr,15,2)" />
        </xsl:variable>
        <xsl:variable name="ss">
            <xsl:value-of select="substring($datestr,18,2)" />
        </xsl:variable>
        <xsl:value-of select="$yyyy" />
        <xsl:value-of select="'-'" />
        <xsl:value-of select="$mm" />
        <xsl:value-of select="'-'" />
        <xsl:value-of select="$dd" />
    </xsl:template>

    <xsl:template match="/">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
            <fo:layout-master-set>
                <fo:simple-page-master master-name="x" page-height="8.5in" page-width="11.5in"
								margin-top="0.5in" margin-bottom="0.5in" margin-left="1in" margin-right="1in">
                    <fo:region-before extent="1in" />
                    <fo:region-body margin-top="0.5in" margin-bottom="0.9in"/>
                    <fo:region-after extent="0.35in" />
                </fo:simple-page-master>
            </fo:layout-master-set>

            <fo:page-sequence master-reference="x">
                <fo:static-content flow-name="xsl-region-before">

                    <fo:block font-size="20pt" font-family="Arial" line-height="27pt" background-color="cyan"
						space-after.optimum="15pt" text-align="center" padding-top="0pt" padding-right="20pt">
                                                    List Order
                    </fo:block>
                </fo:static-content>

                <fo:flow flow-name="xsl-region-body">
                    <fo:block>

                        <fo:table border-collapse="separate" table-layout="fixed">
                            <fo:table-column column-width="1cm"/>
                            <fo:table-column column-width="3cm"/>
                            <fo:table-column column-width="5cm"/>
                            <fo:table-column column-width="3.5cm"/>
                            <fo:table-column column-width="4.5cm"/>
                            <fo:table-column column-width="4cm"/>
                            <fo:table-column column-width="4cm"/>

                            <fo:table-body>
                                <fo:table-row background-color="yellow">
                                    <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                        <fo:block text-align="center" font-size="13pt">
                                            ID
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                        <fo:block text-align="center" font-size="13pt">
                                            Username
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                        <fo:block text-align="center" font-size="13pt">
                                            Fullname
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                        <fo:block text-align="center" font-size="13pt">
                                            Total of Product
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                        <fo:block text-align="center" font-size="13pt">
                                            Total Price of Order (VND)
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                        <fo:block text-align="center" font-size="13pt">
                                            Date of Order
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                        <fo:block text-align="center" font-size="13pt">
                                            Status Order
                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                                <xsl:for-each select="//MngOrder">
                                    <fo:table-row>
                                        <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                            <fo:block text-align="center" padding-top="17pt">
                                                <xsl:value-of select="orderID"/>
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                            <fo:block text-align="center" padding-top="17pt">
                                                <xsl:value-of select="Username"/>
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                            <fo:block text-align="center" padding-top="17pt">
                                                <xsl:value-of select="Fullname"/>
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                            <fo:block text-align="center" padding-top="17pt">
                                                <xsl:value-of select="totalQuantity"/>
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                            <fo:block text-align="center" padding-top="18pt">
                                                <xsl:value-of select="format-number(totalPrice,'###,###,##0')"/>
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                            <fo:block text-align="center" padding-top="18pt">
                                                <xsl:call-template name="formatdate">
                                                    <xsl:with-param name="datestr" select="orderDate"/>
                                                </xsl:call-template>
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell border-color="gray" border-width="0.5pt" border-style="solid">
                                            <fo:block text-align="center" padding-top="18pt">
                                                <xsl:if test="(orderStatus='0')">
                                                    Keep on delivery
                                                </xsl:if>
                                                <xsl:if test="(orderStatus='1')">
                                                    Delivered
                                                </xsl:if>
                                                <xsl:if test="(orderStatus='2')">
                                                    Canceled
                                                </xsl:if>
                                            </fo:block>
                                        </fo:table-cell>
                                    </fo:table-row>
                                </xsl:for-each>
                            </fo:table-body>
                        </fo:table>
                    </fo:block>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>

</xsl:stylesheet>
